//
//  MYMyOtherActionCell.swift
//  MuYing
//
//  Created by tbb on 2019/8/7.
//  Copyright © 2019 TBB. All rights reserved.
//

import UIKit

@objc protocol MYMyOtherActionCellDelegate:NSObjectProtocol {
    func otherSelectAction(_ indexPath:NSIndexPath);
}

class MYMyOtherActionCell: YQTableViewBaseCell,UICollectionViewDelegate, UICollectionViewDataSource {
    @objc weak var delegate:MYMyOtherActionCellDelegate?
    @IBOutlet weak var titleLb: UILabel!
    
    @IBOutlet weak var titleLbBgView: UIView!
    
    @IBOutlet weak var bigBgView: UIView!
    
    @IBOutlet weak var otherLb: UILabel!
    let iconArr = ["My_other_publish_icon",
                   "My_other_make_icon",
                   "My_other_discountCoupon_icon",
                   "My_other_Car_icon",
                   "My_other_adder_icon",
                   "My_other_integralShoping_icon",
                   "My_other_connection_icon",
                   "My_other_set_icon"];
    let textArr = [kYQLSSwift("我的发布"),kYQLSSwift("分享赚钱"),kYQLSSwift("优惠券"),kYQLSSwift("购物车"),kYQLSSwift("收货地址"),kYQLSSwift("积分商城"),kYQLSSwift("联系我们"),kYQLSSwift("设置")];
    
    lazy var otherCollView: UICollectionView = {
        let layout = UICollectionViewFlowLayout();
        layout.scrollDirection = .vertical;
        layout.minimumLineSpacing = 24;
        layout.minimumInteritemSpacing = (kSwiftkScreenSizeWidth-82-4*50) / 3.0;
        layout.itemSize = CGSize(width: 50, height: 53);
        let orderStateCollView = UICollectionView(frame: CGRect(), collectionViewLayout: layout);
        orderStateCollView.backgroundColor = UIColor.clear;
        orderStateCollView.dataSource = self;
        orderStateCollView.delegate = self;
        orderStateCollView.bounces = false;
        orderStateCollView.isScrollEnabled = false;
        orderStateCollView.register(UINib(nibName: "MYMyHeaderViewOrderStateCell", bundle: nil), forCellWithReuseIdentifier: "MYMyHeaderViewOrderStateCell")
        
        return orderStateCollView;
    }()
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.otherLb.text = kYQLSSwift("其他功能");
        self.bigBgView.layer.cornerRadius = 12.0;
        self.bigBgView.clipsToBounds = true;
        
        self.contentView.addSubview(self.otherCollView);
        self.otherCollView.mas_makeConstraints { (make) in
            make?.left.mas_equalTo()(29);
            make?.right.mas_equalTo()(-29);
            make?.top.mas_equalTo()(self.titleLbBgView.mas_bottom)?.mas_equalTo()(12);
            make?.bottom.mas_equalTo()(-18);
        };
    }


    
}

extension MYMyOtherActionCell {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.iconArr.count;
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MYMyHeaderViewOrderStateCell", for: indexPath) as? MYMyHeaderViewOrderStateCell else { return UICollectionViewCell() };
            cell.icon.image = UIImage(named: self.iconArr[indexPath.item]);
            cell.titleLb.text = self.textArr[indexPath.item];
            return cell;
        
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        if let delegate = self.delegate, delegate.responds(to: Selector(("otherSelectAction:"))) {
            self.delegate?.otherSelectAction(indexPath as NSIndexPath);
        }
    
    }

}

